home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / File class library / sources / CFolder.c < prev    next >
Text File  |  1992-10-08  |  3KB  |  116 lines

  1. /*
  2.  
  3.   CFolder.c
  4.   Superclass:    CIsleFile
  5.  
  6.      Implementation of directory manipulation.
  7.  
  8.   October 8, 1992  isl
  9.   
  10. */
  11.  
  12. #include    <CFolder.h>
  13.  
  14. /*=====================*/
  15. /*===---------------===*/
  16.  
  17. void CFolder::IFolder(void)
  18. Begin
  19.     CIsleFile::IIsleFile();
  20. End
  21.  
  22. /*===---------------===*/
  23.  
  24. void    CFolder::CreateNew(OSType creator, OSType type)
  25. Begin
  26.     if (ExistsOnDisk())
  27.     {                                                        //    It already exists -- what is its directory ID?
  28.         CInfoPBRec    specs;                //    The duplicate file specifications
  29.         
  30.         GetMacCatInfo(&specs);
  31.         if (specs.dirInfo.ioFlAttrib & kDirTest)
  32.             folderDirID= specs.dirInfo.ioDrDirID;
  33.         else
  34.             ErrorAlert(dupFNErr, SpecifyMsg(kFolderError, kFolderFileConflict));
  35.     }
  36.     else
  37.         FailOSErr( DirCreate(volNum, dirID, name, &folderDirID) );
  38. End
  39.                                 
  40. /*===---------------===*/
  41.  
  42. void    CFolder::CreateWithIcon(OSType creator, OSType type, short iconID)
  43. Begin
  44.     CCustomIcon*    itsIcon;                        //    The icon for this folder
  45.     short            counter;                                //    Just a loop counter
  46.                 
  47.     CreateNew(creator, type);
  48.     
  49.     TRY
  50.     {
  51.         if (fSuper && dirID)
  52.         {                                                                //    Give this new folder our icon
  53.             itsIcon= Null;
  54.             itsIcon= new CCustomIcon;            //    Create the custom icon object
  55.             itsIcon->ICustomIcon();                //    and initialize it
  56.             
  57.             itsIcon->SpecifyHFS(kCustomIconFile, volNum, folderDirID);
  58.             if (!itsIcon->ExistsOnDisk())    //    Make sure not to overwrite and existing file
  59.             {                                                            //    Let's set a custom icon!
  60.                 CInfoPBRec        specs;                //    The icon file's specs
  61.                 
  62.                 itsIcon->FetchIconFamily(iconID);                         //    Fetch from application's resource fork
  63.                 itsIcon->CreateNew(kNoSignature, kNoType);        //    Create a custom icon file
  64.                 itsIcon->PlaceIconFamily();    //    Place the needed resources
  65.                 
  66.                 itsIcon->GetMacCatInfo(&specs);    //    Get the custom icon's catalog information
  67.                 specs.hFileInfo.ioFlFndrInfo.fdFlags |= kInvisible;
  68.                 itsIcon->SetMacCatInfo(&specs);    //    Make the file invisible
  69.             
  70.                 GetMacCatInfo(&specs);            //    Get the folder's catalog information
  71.                 specs.dirInfo.ioDrUsrWds.frFlags &= kFlagsOff;        //    Turn off all Finder flags
  72.                 specs.dirInfo.ioDrUsrWds.frFlags |= kCustomIcon;    //    Turn the hasCustomIcon bit on
  73.                 SetMacCatInfo(&specs);            //    Register a custom icon for our folder
  74.  
  75.                 ForgetObject(itsIcon);
  76.             }
  77.         }
  78.         else
  79.             ErrorAlert(noErr, SpecifyMsg(kFolderError, kBadSystem));
  80.     }
  81.     CATCH
  82.     {
  83.         ForgetObject(itsIcon);
  84.     }
  85.     ENDTRY;
  86. End
  87.  
  88. /*===---------------===*/
  89.  
  90. Boolean CFolder::ExistsOnDisk(void)
  91. Begin
  92.     CInfoPBRec    specs;                                //    File specifications
  93.     OSErr                error;                                //    A possible error condition
  94.     
  95.     specs.dirInfo.ioCompletion=    Null;
  96.     specs.dirInfo.ioNamePtr=        name;
  97.     specs.dirInfo.ioVRefNum=        volNum;
  98.     specs.dirInfo.ioFDirIndex=    kDefault;
  99.     specs.dirInfo.ioDrDirID=        dirID;
  100.         
  101.     error= PBGetCatInfo(&specs, False);
  102.     return (error != fnfErr);
  103. End
  104.  
  105. /*===---------------===*/
  106.  
  107. void CFolder::GetPath(Str255 path, Str255 delimiter)
  108. Begin
  109.     inherited::GetPath(path, delimiter);
  110.     
  111.     if (path[*path] != delimiter[*delimiter])
  112.         ConcatPStrings(path, delimiter);
  113. End
  114.  
  115. /*===---------------===*/
  116. /*=====================*/